<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <link href="${r"$"}{pageContext.request.contextPath}/resource/css/def/ztree/metro.css" rel="stylesheet">
  	<link href="${r"$"}{pageContext.request.contextPath}/resource/css/def/bootstrap/ace/ace-part2.min.css" rel="stylesheet">
  	<link href="${r"$"}{pageContext.request.contextPath}/resource/css/def/bootstrap/ace/ace.css" rel="stylesheet">
  	<link href="${r"$"}{pageContext.request.contextPath}/resource/css/def/frm/common/common.css" rel="stylesheet">
  	<script src="${r"$"}{pageContext.request.contextPath}/resource/js/jquery/plugin/handlebars-v3.0.1.js"></script>
  	<script src="${r"$"}{pageContext.request.contextPath}/resource/js/bootstrap/validator/bootstrapValidator.js"></script>
  </head>
<script type="text/javascript">
window.onload = function(){ 
	if(null == $("#objectForm").data('bootstrapValidator')) {
		$("#objectForm").bootstrapValidator(checkValidator);
	}
	resetValidator();
} 
function resetValidator(){
	if($("#objectForm").data('bootstrapValidator')){
		$("#objectForm").data('bootstrapValidator').resetForm(false);
	}
}
var checkValidator = {
		message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        submitHandler: function(validator, form, submitButton) {
   			  save();
    		},
        fields: {
        	<#list beanList as column>
        	  <#if column.isList='1'>
        			${column.newColumnName}:{
        				validators: {
        					 notEmpty :{message: '请输入'+'${column.displayComment}'}
        				}	
        			},
        		</#if>
        	</#list>
        }
}
//保存
function save(){
	$.ajax({
		url:"addObject.action",
		data:$("#objectForm").serialize(),
		dataType:"JSON",
		type:"post",
		success:function(data){
			if(data == '1'){
				alert('新增信息成功！');
				window.opener.searchTable.draw(false);
				window.close();
			}else if(data == '0'){
				alert("新增信息失败！");
			}
		},
		error:function(e){
			alert("新增信息失败");
		}
	})
}
//关闭当前页面
function closeAddPage(){
	window.close();
}
</script>
  <body>
  	<div class="container-fluid staffUpdate" id="staffContainer">
  		<div class="orderchek-body-row">
  			<form class="form-horizontal" role="form" id="objectForm" autocomplete="off">
  				<div class="orderchek-border">
  				 	<div id="addModalTitle" class="orderchek-title">新增页面</div>
  				 	<div class="ordercheck-table table-responsive">
  				 		<div class="demo-row modal-body" id="addField">  				 			
      					 <#--组装表单-->
      					 <#list beanList as column>
      						 <#--台帐显示字段-->
      						 <#if column.isList='1'>
							       <div class="form-group">
								       <div class="input-group">
									       <label class="input-group-addon" for="nameStaffObj">${column.displayComment}</label>								
									       <input type="text" name="${column.newColumnName}" id="${column.newColumnName}" placeholder="${column.displayComment}" class="form-control" required>
								       </div>
							       </div>
						       </#if>
					       </#list>
					      <div class="center">					
							    <button class="btn btn-primary ma_btn2" type="submit" id="saveBtn">保存</button>
							    <button class="btn btn-primary" type="button" id="backBtn" onclick="closeAddPage();">关闭</button>
					      </div>
					    </div>
					  </div>
					</div>
				</form>
			</div>
  	</div>
  </body>
</html>
